/**
 * 选择文件存储路径
 */

let newHandle:any = ''
export async function saveFile (blob:Blob) {
  console.log('select file save path')
  if (!newHandle) {
    newHandle = await window.showSaveFilePicker({
      suggestedName: new Date().getTime()+'.oasis'
    })
  }
  const writableStream = await newHandle.createWritable()
  await writableStream.write(blob)
  await writableStream.close()
  return Promise.resolve(true)
}

/**
  * 读文件
  * @returns
  */
export async function readFile () {
  let [FileSystemFileHandle] = await window.showOpenFilePicker({
    description: 'Text Files',
    accept: {
      'text/plain': ['.oasis'],
    },
  })
  const file = await FileSystemFileHandle.getFile()
  return file.text()
}

